package dome1;

import javax.swing.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-06-22
 * Time: 20:37
 */

//泛型的上界
//代表将来传进来的类型必须实现了Comparab接口  ,  指定的E要么是子类要么是本身!!!

class Alg<E extends Comparable<E>> {
    public E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Test4 {
    public static void main(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {4,6,1,34,8,90,43,233,5,7,5};
        Integer val = alg.findMax(array);
        System.out.println(val);

        System.out.println("===========");

        Alg<Double> alg1 = new Alg<>();
        Double[] arr = {12.5,34.6,23.6,45.9,1.1};
        Double d = alg1.findMax(arr);
        System.out.println(d);
    }
}
